package com.neusoft.dibuy.partitioner;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class PhoneDataReducer extends Reducer<Text, FlowBean, Text, Text> {

    final private Text text = new Text();

    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Reducer<Text, FlowBean, Text, Text>.Context context) throws IOException, InterruptedException {
        long upFlow = 0;
        long downFlow = 0;
        for (FlowBean value : values) {
            upFlow += value.getUpFlow();
            downFlow += value.getDownFlow();
        }
        long sum = upFlow + downFlow;
        text.set(key.toString() + "\t" + upFlow + "\t" + downFlow + "\t" + sum);
        context.write(key, text);
    }
}
